﻿#pragma once

#include <ppltasks.h>
#include "winrtsock.h"
//#include <tnet_utils.h>
//#include "winrt\tnet_utils_winrt.h"

using namespace Windows::Foundation;
using namespace Windows::Networking::Sockets;
using namespace Windows::Networking;
using namespace Windows::Storage::Streams;
using namespace Platform;

namespace WinRTSock_RuntimeComponents_Test {
	public ref class WinRTSockTests sealed
	{
	public:
		WinRTSockTests();

		// Tests
		IAsyncOperation<Boolean>^ SIPConnectTest();
		IAsyncOperation<Boolean>^ CreateStreamSocketTest();
		IAsyncOperation<Boolean>^ CreateDatagramSocketTest();
		IAsyncOperation<Boolean>^ CreateInvalidSocketTest();
		IAsyncOperation<Boolean>^ SockAddrInfoInitWithIpv4Test();
		IAsyncOperation<Boolean>^ SockAddrInfoInitWithIpv6Test();
		IAsyncOperation<Boolean>^ SockAddrInfoInitWithHostNameTest();
		IAsyncOperation<Boolean>^ GetFamilyWithIpv4Test();
		IAsyncOperation<Boolean>^ GetFamilyWithIpv6Test();
		IAsyncOperation<Boolean>^ GetFamilyWithHostNameTest();
		IAsyncOperation<Boolean>^ ConnectStreamSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ ConnectDatagramSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ ConnectStreamSocketWithIpv6Test();
		IAsyncOperation<Boolean>^ ConnectDatagramSocketWithIpv6Test();
		IAsyncOperation<Boolean>^ ConnectStreamSocketWithHostNameTest();
		IAsyncOperation<Boolean>^ ConnectDatagramSocketWithHostNameTest();
		IAsyncOperation<Boolean>^ GetSockNameWithIpv4StreamSocketTest();
		IAsyncOperation<Boolean>^ GetSockNameWithIpv4DatagramSocketTest();
		IAsyncOperation<Boolean>^ GetSockNameWithIpv6StreamSocketTest();
		IAsyncOperation<Boolean>^ GetSockNameWithIpv6DatagramSocketTest();
		IAsyncOperation<Boolean>^ GetSockNameWithHostNameStreamSocketTest();
		IAsyncOperation<Boolean>^ GetSockNameWithHostNameDatagramSocketTest();
		IAsyncOperation<Boolean>^ GetHostNameTest();
		IAsyncOperation<Boolean>^ GetSockIpAndPortWithIpv4Test();
		IAsyncOperation<Boolean>^ GetSockIpAndPortWithIpv6Test();
		IAsyncOperation<Boolean>^ GetSockIpAndPortWithHostNameTest();
		IAsyncOperation<Boolean>^ GetPeerNameWithIpv4StreamSocketTest();
		IAsyncOperation<Boolean>^ GetPeerNameWithIpv4DatagramSocketTest();
		IAsyncOperation<Boolean>^ GetPeerNameWithIpv6StreamSocketTest();
		IAsyncOperation<Boolean>^ GetPeerNameWithIpv6DatagramSocketTest();
		IAsyncOperation<Boolean>^ GetPeerNameWithHostNameStreamSocketTest();
		IAsyncOperation<Boolean>^ GetPeerNameWithHostNameDatagramSocketTest();

		//IAsyncOperation<Boolean>^ BindDatagramSocketTest();
		//IAsyncOperation<Boolean>^ AcceptStreamSocketTest();

		IAsyncOperation<Boolean>^ SendStreamSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ SendToDatagramSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ WSASendStreamSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ WSASendToDatagramSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ SendStreamSocketWithIpv6Test();
		IAsyncOperation<Boolean>^ SendToDatagramSocketWithIpv6Test();
		IAsyncOperation<Boolean>^ WSASendStreamSocketWithIpv6Test();
		IAsyncOperation<Boolean>^ WSASendToDatagramSocketWithIpv6Test();

		IAsyncOperation<Boolean>^ RecvStreamSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ RecvFromDatagramSocketWithIpv4Test();
		IAsyncOperation<Boolean>^ RecvStreamSocketWithIpv6Test();
		IAsyncOperation<Boolean>^ RecvFromDatagramSocketWithIpv6Test();

	private:
		void TestFixtureInit();
		static void TestInit();
		static void TestCleanup();
		void OnConnection(StreamSocketListener^ listener, StreamSocketListenerConnectionReceivedEventArgs^ object);
		void OnMessageReceived(DatagramSocket^ socket, DatagramSocketMessageReceivedEventArgs^ object);
		void Send(String^ message);

		StreamSocketListener^ ipv4StreamListener;
		StreamSocketListener^ ipv6StreamListener;
		DatagramSocket^ ipv4DatagramListener;
		DatagramSocket^ ipv6DatagramListener;
	};
}